home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / COM / ProTERM Mac1.2a.sit / ProTERM Mac1.2a / Macros / Contributed / David's Utilities / Catalogger next >
Text File  |  1996-07-20  |  6KB  |  195 lines

  1. // Catalogger Utility
  2. // Version 1.1 by David D. Miller  20-JUL-96
  3. // dmiller@c4systm.com - email for updates and support
  4.  
  5. // Catalogger will make a text file listing of the contents of a directory.
  6.  
  7. FUNC main()
  8. {
  9.   WIN_RUNNING(0);
  10.  
  11.   SHARED STR tab = ". ";  // <-- set this to what you want it to put in front
  12.                           // of each line (one per level) [default]
  13.   SHARED INT gcount = 0;
  14.   SHARED INT tcount = 0;
  15.   SHARED INT fref, show_alias, show_type, alias_follow;
  16.   INT setupwin;
  17.   STR svfl, fldr, tmpl;
  18.   fldr = "";
  19.   svfl = FN_GETPATH(0)+"Catalog";
  20.   tmpl = D_NEW(100,100,150,502,256,"PT Catalogger") +
  21.          D_INPUT("WT+0 WL+1",1024,300,24,"Path to catalog:") +
  22.          D_BUTTON("WT+1 PR+4","Set Path") +
  23.          D_INPUT("PB+5 WL+0",1024,300,24,"Save catalog to:") +
  24.            D_PRESET(svfl) +
  25.          D_BUTTON("PB-23 PR+4","Set Save") +
  26.          D_INPUT("PB+15 WL+15",15,60,24,"Indent string:") +
  27.            D_PRESET(tab) +
  28.          D_TOGGLE("WT+55 WL+200","Follow folder aliases") +
  29.          D_TOGGLE("PB+0 WL+200","Show alias original") +
  30.            D_PRESET("1") +
  31.          D_TOGGLE("PB+0 WL+200","Show type/creator") +
  32.          D_DEFAULT("WB+0 WR-5","OK") +
  33.          D_BUTTON("WB-3 PL-10","Cancel");
  34.   setupwin = D_OPEN(tmpl);
  35.   D_SET(setupwin,"Show alias original","1");
  36.   WHILE (1)
  37.   {
  38.     SWITCH (D_EVENT(setupwin,12000,"BT"))
  39.     {
  40.       CASE "@CLOSE":
  41.       CASE "Cancel": {
  42.                        D_CLOSE(setupwin);
  43.                        END;
  44.                      }
  45.       CASE "OK"    : {
  46.                        fldr = D_GET(setupwin,"Path to catalog:");
  47.                        IF (fldr == "") { WIN_NOTE(4,"You haven't entered a "+
  48.                              "path yet!"); CONTINUE; }
  49.                        svfl = D_GET(setupwin,"Save catalog to:");
  50.                        IF (svfl == "") { WIN_NOTE(4,"You haven't entered a "+
  51.                              "save filename yet!"); CONTINUE; }
  52.                        tab = D_GET(setupwin,"Indent string:");
  53.                        alias_follow = NUM_STR(D_GET(setupwin,
  54.                                        "Follow folder aliases"));
  55.                        show_alias = NUM_STR(D_GET(setupwin,
  56.                                        "Show alias original"));
  57.                        show_type = NUM_STR(D_GET(setupwin,
  58.                                        "Show type/creator"));
  59.                        D_CLOSE(setupwin);
  60.                        BREAK;
  61.                      }
  62.       CASE "Follow folder aliases": {
  63.                        IF (D_GET(setupwin,"Follow folder aliases") == "1")
  64.                          { WIN_NOTE(4,"WARNING: Following folder aliases^M"+
  65.                                       "can cause an infinite loop is a^M"+
  66.                                       "circular reference is found.") }
  67.                      }
  68.       CASE "Set Path": {
  69.                        FN_SETPATH(0,D_GET(setupwin,"Path to catalog:"));
  70.                        fldr = FN_PATH(0,"Select");
  71.                        D_SET(setupwin,"Path to catalog:",fldr);
  72.                      }
  73.       CASE "Set Save": {
  74.                        FN_SETPATH(0,D_GET(setupwin,"Save Catalog to:"));
  75.                        svfl = FN_SAVE(0,"Save Catalog As:",FN_WHAT(svfl));
  76.                        D_SET(setupwin,"Save Catalog to:",svfl);
  77.                      }
  78.     }
  79.   }
  80.   IF (alias_follow > -1)
  81.   {
  82.     SetupWin();
  83.     IF (F_EXISTS(svfl) != "") { F_DELETE(svfl); }
  84.     F_CREATE(svfl);
  85.     fref = F_OPEN(svfl,"rw");
  86.     f_print(fref,"Directory of "+FN_UNPK(fldr)+"^M");
  87.     scan(fldr,tab);
  88.     F_CLOSE(fref);
  89.     CloseWin();
  90.     INT view = WIN_NOTE(5,"Done!  View the catalog file now?");
  91.     IF (view == 1) { UI_OPEN(svfl); }
  92.   }
  93.   RETURN();
  94. }
  95.  
  96. FUNC scan(STR fldr, STR lnprf)
  97. {
  98.   SHARED STR tab;
  99.   SHARED INT gcount, tcount, fref, alias_follow, show_alias, show_type;
  100.   SetWin("Scanning "+fldr+"...");
  101.   STR batch = FN_SCAN(fldr,"","");
  102.   INT count = 0;
  103.   INT error;
  104.   INT size = ARRAY_SIZE(batch,1);
  105.   tcount = tcount + size;
  106.   STR file, type, info;
  107.   WHILE (count < size)
  108.   {
  109.     count = count + 1;
  110.     gcount = gcount + 1;
  111.     IF (WinEvt() == "Stop") { CloseWin(); F_CLOSE(fref); END; }
  112.     SetProg((gcount * 100)/tcount);
  113.     file = FN_UNPK(ARRAY_GET(batch,count));
  114.     type = F_EXISTS(file);
  115.     info = F_GETINFO(file);
  116.     IF (type == "fldr")
  117.     {
  118.       IF (info != "") && (!alias_follow)
  119.       {
  120.         f_print(fref,lnprf+FN_WHAT(file)+":");
  121.         IF (show_alias)
  122.         {
  123.           f_print(fref," --> "+FN_UNPK(FN_RESOLVE(file,"")));
  124.         }
  125.         f_print(fref,"^M");
  126.       }
  127.       ELSE
  128.       {
  129.         f_print(fref,lnprf+FN_WHAT(file)+":");
  130.         IF (info != "") && (show_alias)
  131.         {
  132.           f_print(fref," --> "+FN_UNPK(FN_RESOLVE(file,"")));
  133.         }
  134.         f_print(fref,"^M");
  135.         scan(file+":",lnprf+tab)
  136.       }
  137.     }
  138.     ELSE
  139.     {
  140.       f_print(fref,lnprf+FN_WHAT(file));
  141.       IF (show_type)
  142.       {
  143.         f_print(fref," ("+STR_MID(info,2,4)+"/"+STR_MID(info,6,4)+")");
  144.       }
  145.       f_print(fref,"^M");
  146.     }
  147.   }
  148.   RETURN();
  149. }
  150.  
  151. FUNC f_print(INT fref, STR text)
  152. {
  153.   IO_WRITE(fref,STR_LEN(text),text);
  154.   RETURN();
  155. }
  156.  
  157. FUNC SetupWin()
  158. {
  159.   STR tmpl = D_NEW(0,20,60,600,128+256,"Catalogger Status")+
  160.              D_FORM("WT+0 WL+0",550,-1,"~form")+
  161.              D_PROG("WB-3 WL+0",13,500,"~prog")+
  162.              D_BUTTON("WB+0 WR+0","Stop");
  163.   SHARED INT statwin = D_OPEN(tmpl);
  164.   RETURN();
  165. }
  166.  
  167. FUNC CloseWin()
  168. {
  169.   SHARED INT statwin;
  170.   D_CLOSE(statwin);
  171.   RETURN();
  172. }
  173.  
  174. FUNC SetWin(STR text)
  175. {
  176.   SHARED INT statwin;
  177.   D_SET(statwin,"~form",text);
  178.   RETURN();
  179. }
  180.  
  181. FUNC WinEvt()
  182. {
  183.   SHARED INT statwin;
  184.   STR event = D_EVENT(statwin,1,"B");
  185.   IF (event == "~prog") { event = "" };
  186.   RETURN(event);
  187. }
  188.  
  189. FUNC SetProg(INT val)
  190. {
  191.   SHARED INT statwin;
  192.   D_SET(statwin,"~prog",STR_NUM(val));
  193.   RETURN();
  194. }
  195.